package org.jeecg.modules.demo.notify;

import lombok.Data;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

@Data
public class WeChatNotify {
    private String webhook;
    private String msgType;
    private String content;

    public void notifyMsg() {
        switch (msgType){
            case "markdown":
                notifyMarkDownMsg();
            break;
        }
    }
    private void notifyMarkDownMsg() {
        RestTemplate template = new RestTemplate();

        HashMap<String, Object> body = new HashMap<>();
        HashMap<String, Object> content = new HashMap<>();

        content.put("content",this.content);
        String[] userAll = new String[1];
        userAll[0] = "@FengXiaoShuiHan";
        content.put("mentioned_list",userAll);
        body.put("msgtype", "markdown");
        body.put("markdown",content);

        // 添加请求头
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", "application/json");

        // 组装请求头和参数
        HttpEntity<Map<String, Object>> formEntity = new HttpEntity<>(body, headers);
        ResponseEntity<String> result = template.postForEntity(webhook,formEntity,String.class);
        System.out.println(result.getBody());
    }

}

